package com.briup.day14;

import com.briup.day14.bean.Animal;
import com.briup.day14.bean.Cat;
import com.briup.day14.bean.Dog;

//猫狗综合案例
public class Test03_Animal {
    public static void main(String[] args) {
        //抽象类不能实例化对象
        //Animal a = new Animal();

        //1.抽象类引用 指向 子类对象
        Animal a = new Cat("yellow",2,3);
        System.out.println("猫咪: " + a);

        a.eat();
        a.sleep();

        System.out.println("------------");

        //2.
        a = new Dog("black",1,7);
        System.out.println("狗狗: " + a);
        a.eat();
        a.sleep();

        System.out.println("-------------");
        //3.类型转换问题
        //Cat c = (Cat)a; //强制类型转换：父子类
        //String s = (String)a; ERROR
        //c.eat();
        if(a instanceof Cat) {
            Cat c = (Cat)a;
            c.eat();
        }else if(a instanceof Dog) {
            Dog d = (Dog)a;
            d.eat();
        }
    }
}
